package com.ctshk.rpc.order.tour.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.order.tour.base.CustomBaseMapper;
import com.ctshk.rpc.order.tour.dto.SeriesOrderTouristQuitListDTO;
import com.ctshk.rpc.order.tour.entity.SeriesOrderTouristQuit;
import com.ctshk.rpc.order.tour.req.SeriesOrderTouristQuitListReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

/**
 * <p>
 * 系列团游客退团 Mapper 接口
 * </p>
 *
 * @author 谭响
 * @since 2021-01-29
 */
public interface SeriesOrderTouristQuitMapper extends CustomBaseMapper<SeriesOrderTouristQuit> {

    @Select("<script>"+
         "SELECT tsotq.id , tsoti.order_id, tsoti.schedule_id, tsoti.id as touristId,  " +
         "tsoti.cn_surname, tsoti.cn_name,tsoti.total_paid_in,  " +
         "tsotq.deduction_amount, tsotq.refund_amount, tsotq.discount_amount, tsotq.refund_type_id, tsotq.refund_type, " +
         "tsotq.refund_account, tsotq.quit_reason, tsotq.remark, " +
         "tsotq.gmt_create, tsotq.create_id, tsotq.refund_status " +
         "FROM t_series_order_tourist_info tsoti " +
         "LEFT JOIN ( " +
         "SELECT temp.id,temp.tourist_id,temp.deduction_amount,temp.refund_amount,temp.discount_amount,temp.refund_type_id,temp.refund_type,temp.refund_account,temp.quit_reason,temp.remark,temp.gmt_create,temp.create_id,temp.refund_status,temp.is_deleted " +
         "FROM t_series_order_tourist_quit temp " +
         "WHERE temp.is_deleted = 0 AND temp.order_id = #{req.orderId, jdbcType=BIGINT} " +
         "<if test=\"req.refundStatus != null\">AND temp.refund_status = #{req.refundStatus, jdbcType=INTEGER}</if>  " +
         "ORDER BY temp.gmt_create DESC " +
         ") tsotq ON tsotq.tourist_id = tsoti.id " +
         "WHERE tsoti.is_full_info = 1 AND tsoti.order_id = #{req.orderId, jdbcType=BIGINT} AND tsoti.is_deleted = 0"+
         "<if test=\"req.condition1 != null\">AND (tsoti.cn_fullname like CONCAT('%',#{req.condition1, jdbcType=VARCHAR},'%') OR tsoti.en_fullname like CONCAT('%',#{req.condition1, jdbcType=VARCHAR},'%')) </if>  " +
         "</script>")
    IPage<SeriesOrderTouristQuitListDTO> selectListBySelective(@Param("page") IPage<SeriesOrderTouristQuitListDTO> page, @Param("req") SeriesOrderTouristQuitListReq req);

    /**
     *
     * @param page
     * @param req
     * @return
     */
    @Select("<script>"+
            "SELECT tsotq.id , tsoti.order_id, tsoti.schedule_id, tsoti.id as touristId,  " +
            "tsoti.cn_surname, tsoti.cn_name,tsoti.total_paid_in,  " +
            "tsotq.deduction_amount, tsotq.refund_amount, tsotq.discount_amount, tsotq.refund_type_id, tsotq.refund_type, " +
            "tsotq.refund_account, tsotq.quit_reason, tsotq.remark, " +
            "tsotq.gmt_create, tsotq.create_id, tsotq.refund_status " +
            "FROM t_series_order_tourist_info tsoti " +
            "LEFT JOIN ( " +
                "SELECT temp.id,temp.tourist_id,temp.deduction_amount,temp.refund_amount,temp.discount_amount,temp.refund_type_id,temp.refund_type,temp.refund_account,temp.quit_reason,temp.remark,temp.gmt_create,temp.create_id,temp.refund_status,temp.is_deleted " +
                "FROM t_series_order_tourist_quit temp " +
                "WHERE temp.is_deleted = 0 AND temp.order_id = #{req.orderId} " +
                "<if test=\"req.refundStatus != null\">AND temp.refund_status = #{req.refundStatus}</if>  " +
                "ORDER BY temp.gmt_create DESC " +
            ") tsotq ON tsotq.tourist_id = tsoti.id " +
            "WHERE tsoti.is_full_info = 1 AND tsoti.order_id = #{req.orderId} AND tsoti.is_deleted = 0"+
            "<if test=\"req.condition != null\">AND (tsoti.cn_fullname LIKE CONCAT('%',#{req.condition},'%') OR tsoti.en_fullname LIKE CONCAT('%',#{req.condition},'%')) </if>  " +
            "</script>")
    IPage<SeriesOrderTouristQuitListDTO> queryQuitList( @Param("req") SeriesOrderTouristQuitListReq req,IPage<SeriesOrderTouristQuitListDTO> page);
}
